__all__ = ["pretty_print"]


def pretty_print(factor_result):
    if not factor_result:
        return "1"
    elif len(factor_result) == 1:
        poly, deg = factor_result[0]
        string = str(poly)
        if deg == 1:
            return string
        elif '+' in string or " -" in string:
            return "({0})^{1}".format(string, deg)
        else:
            return "{0}^{1}".format(string, deg)
    result = []
    for poly, deg in factor_result:
        string = str(poly)
        if '+' in string or " -" in string:
            if deg == 1:
                result.append("({0})".format(string))
            else:
                result.append("({0})^{1}".format(string, deg))
        elif deg == 1:
            result.append(string)
        else:
            result.append(string + '^' + str(deg))
    return " * ".join(result)
